<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .origin{
            width: 209px;
            display: flex;
            justify-content: space-between;
        }
        .origin:nth-child(even){
            background-color: rgb(183, 236, 157);
        }
        .origin:nth-child(odd){
            background-color: rgb(185, 241, 237);
        }
        .origin.red{
            background-color:red;
            text-decoration: line-through;
        }

        .x{
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div id="app">
        <input v-model='val' @keyup.enter='addTask' placeholder="请输入任务..."/><button @click="addTask">add</button>

        <div class="list-container"   >
            <div v-for="(item,index) in list"  :class="['origin',{red:item.checked}]"   @click="dissapear(item)"> 
                <div class="task-name">{{ item.name }}</div>
                <div class="x" @click.stop="taskDelete(index)" >X</div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    <script>
        let vm = new Vue({
            el:'#app',
            data(){
                return {
                    val : '',
                    list:[], // * 初始化任务列表
                }
            },
            methods:{
                addTask(){
                    if(this.val){
                        this.list.push({
                            name : this.val,
                            checked : false,
                            
                        })
                        this.val = ''; 
                    } 
                },
                dissapear(item){
                    item.checked = !item.checked
                },
                taskDelete(index){
                    this.list.splice(index,1);

                }
            }
        });
    </script>
</body>
</html> 